<?php

Raise::load('core.RaiseStack');

/**
 * TestCoreRaiseStack class
 * Testing unit of 'phpraise/control/RaiseStack.php'
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.UnitTest.Test
 */
class TestCoreRaiseStack extends RaiseTest {
    
    public static function testClass(){
        self::assertClassExists('RaiseStack');
        self::assertClassExtends('RaiseStack', 'RaiseDataType');

        $stack = new RaiseStack();
        self::assertObjectClass($stack, 'RaiseStack');

        self::assertClassMethod($stack, 'push');
        self::assertClassMethod($stack, 'pop');
        self::assertClassMethod($stack, 'count');
        self::assertClassMethod($stack, 'top');
    }

    public static function testOps(){
        $stack = new RaiseStack();
        $stack->push(20);

        self::assertStrictEqual($stack->top(), 20);
        self::assertStrictEqual($stack->count(), 1);

        $stack->push(50);
        $stack->push(90);

        self::assertStrictEqual($stack->top(), 90);
        self::assertStrictEqual($stack->count(), 3);

        $a = $stack->pop();
        self::assertStrictEqual($a, 90);
        self::assertStrictEqual($stack->count(), 2);

        $a = $stack->pop();
        self::assertStrictEqual($a, 50);
        self::assertStrictEqual($stack->count(), 1);

        $a = $stack->pop();
        self::assertStrictEqual($a, 20);
        self::assertStrictEqual($stack->count(), 0);

        self::assertNull($stack->pop());
        self::assertNull($stack->top());
    }

}